home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / systems / mint / ksh / examples / last.ksh < prev    next >
Encoding:
Text File  |  1995-11-25  |  453 b   |  36 lines

  1. #!/bin/sh
  2. # find the last argument AND reset all arguments but the one found,
  3. # using only BUILTIN constructs
  4. # set -x    # switch on debugging
  5.  
  6. case $# in
  7.     0)
  8.         echo 'No arguments specified.' >&2
  9.         exit 1
  10. esac
  11.  
  12. argv=
  13. last=
  14.  
  15. while :
  16. do
  17.     case $# in
  18.         1)
  19.             last=$1
  20.             break
  21.     esac
  22.     eval i$#=\$1
  23.     argv="$argv \"\$i$#\""
  24.     shift
  25. done
  26.  
  27. eval set x $argv
  28. shift
  29.  
  30. echo "last=$last"
  31. echo 'new arguments:'
  32. for i
  33. do
  34.     echo "  $i"
  35. done
  36.